package com.cherrish.demo;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cherrish
 * @time 2019-04-08 14:20
 * @name TestFinally
 * @desc:
 */
public class TestFinally {
    public static void main(String[] args) {
//        System.out.println(test4());
//        System.out.println(getMap().get("KEY").toString());
    }

    public static int test4(){
        int b = 20;
        try {
            System.out.println("try block");
            b = b / 0;
            return b+=80;
        }catch (Exception e){
            b += 15;
            System.out.println("catch block");
        }finally {
            System.out.println("finally block");
            if(b > 25){
                System.out.println("b > 25, b="+ b);
            }
            b += 50;
        }
        return 204;
    }

    public static int test3(){
        int b = 20;
        try {
            System.out.println("try block");
            return b+=80;
        }catch (Exception e){
            System.out.println("catch block");
        }finally {
            System.out.println("finally block");
            if(b > 25){
                System.out.println("b > 25, b="+ b);
            }
            b = 150;
        }
        return 2000;
    }

    public static int test2(){
        int b = 20;
        try {
            System.out.println("try block");
            return b+=80;
        }catch (Exception e){
            System.out.println("catch block");
        }finally {
            System.out.println("finally block");
            if(b > 25){
                System.out.println("b > 25, b="+ b);
            }
            return 200;
        }
    }

    public static int test1(){
        int b = 20;
        try {
            System.out.println("try block");
            return b+=80;
        }catch (Exception e){
            System.out.println("catch block");
        }finally {
            System.out.println("finally block");
            if(b > 25){
                System.out.println("b > 25, b="+ b);
            }
        }
        return b;
    }

    public static String test11(){
        int b = 20;
        try {
            System.out.println("try block");
            return test12();
        }finally {
            System.out.println("finally block");
        }
    }

    public static String test12(){
        System.out.println("return statement");
        return "after return";
    }

    public static Map<String, String> getMap(){
        Map<String, String> map = new HashMap<>();
        map.put("KEY", "INIT");
        try {
            map.put("KEY", "TRY");
            return map;
        }catch (Exception e){
            map.put("KEY", "CATCH");
        }finally {
            map.put("KEY", "FINNALLY");
            map = null;
        }
        return map;
    }
}
